#include "cpu/exec/template-start.h"

#define instr test

static void do_execute(){
    DATA_TYPE result;
    if(ops_decoded.opcode == 0xa8 || ops_decoded.opcode == 0xa9){
        op_dest->type = OP_TYPE_REG;
        op_dest->reg = 0;
        op_dest->val = REG(0);
    }
    result = (DATA_TYPE)op_src->val & (DATA_TYPE)op_dest->val;
   // OPERAND_W(op_dest,result);
    cpu.eflags.OF = 0;
    cpu.eflags.CF = 0;
    //设置ZF
    if((DATA_TYPE)result == 0){
        cpu.eflags.ZF = 1;
    }
    else{
        cpu.eflags.ZF = 0;
    }

    //设置SF,注意由于操作数位数不一样，最高位位置不一样
    cpu.eflags.SF = result >> (DATA_BYTE * 8 -1);

    //设置PF，结果的低8位包含偶数个1
    uint32_t i;
    uint32_t k = 0;
    for(i = 0; i < 8; ++i){
        k += (result >> i) & 0x1;
    }
    if(k % 2 == 0){
        cpu.eflags.PF = 1;
    }
    else{
        cpu.eflags.PF = 0;
    }
    print_asm_template2();
}

make_instr_helper(r2rm)
make_instr_helper(i2rm)
make_instr_helper(i)

#include "cpu/exec/template-end.h"